#pragma once

#include "types.h"

namespace cpfs {

class Device {
public:
    typedef int64_t Offset;
    Device(char const *path, Offset size, Offset offset);
    virtual ~Device();
    Offset size() const;
    void flush();
    void read_block(Blkno blkno, void *buf, size_t blksize) const {
		read(buf, blksize, blkno * blksize);
	}
    void write_block(Blkno blkno, void const *buf, size_t blksize) {
		write(buf, blksize, blkno * blksize);
	}
    void read(void *buf, size_t count, Offset off) const;
    void write(void const *buf, size_t count, Offset off);
private:
    boost::scoped_ptr<struct DeviceImpl> impl_;
    Offset off_;
    Offset size_;
};

} // namespace cpfs {
